<template>
  <section>
    <div class="container">
      <div class="handle-box">
        <el-input
          v-model="real_name"
          placeholder="用户"
          clearable
          class="handle-input mr10"
          @keyup.enter.native="handleSearch"
        ></el-input>
        <el-input
          v-model="mobile"
          placeholder="手机号"
          clearable
          class="handle-input w200 mr10"
          @keyup.enter.native="handleSearch"
        ></el-input>
        <el-input
          v-model="card_number"
          placeholder="卡号"
          clearable
          class="handle-input w200 mr10"
          @keyup.enter.native="handleSearch"
        ></el-input>
        <el-select
          v-model="type"
          placeholder="筛选卡片类型"
          clearable
          @keyup.enter.native="handleSearch"
          class="mr10"
        >
          <el-option label="全部" value=""></el-option>
          <el-option label="储蓄卡" value="00"></el-option>
          <el-option label="信用卡" value="02"></el-option>
        </el-select>
        <el-button type="primary" icon="search" @click="handleSearch"
          >搜索</el-button
        >
        <el-button type="danger" @click="handleReset">清空</el-button>
      </div>
      <el-table
        :data="tableData"
        border
        class="table"
        ref="multipleTable"
        v-loading="loading"
      >
        <el-table-column prop="id" label="ID"></el-table-column>
        <el-table-column prop="real_name" label="姓名"></el-table-column>
        <el-table-column prop="bank_mobile" label="预留电话"></el-table-column>
        <el-table-column prop="card_number" label="卡号"></el-table-column>
        <el-table-column prop="bank_name" label="银行名称"></el-table-column>
        <el-table-column prop="quota" label="额度"></el-table-column>
        <el-table-column prop="statement_date" label="出账日"></el-table-column>
        <el-table-column prop="repayment_date" label="还款日"></el-table-column>
        <el-table-column prop="create_time" label="绑卡时间"></el-table-column>
        <!-- <el-table-column prop="plan_status" label="计划状态" :formatter="planStatusFormat"></el-table-column> -->
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          layout="sizes, prev, pager, next"
          :total="pagination.total"
          :current-page.sync="pagination.currentPage"
          :page-size="pagination.pageSize"
          :page-sizes="pagination.pageSizes"
        >
        </el-pagination>
      </div>
    </div>
  </section>
</template>

<script>
import { userTiedCardList } from '@/api/modules/user'
import moment from 'moment'

export default {
  name: 'card',
  components: {},
  data() {
    return {
      loading: true,
      fatherLoading: false,
      dialogVisible: false,
      tableData: [],
      real_name: '',
      mobile: '',
      card_number: '',
      type: '02',
      father_real_name: '',
      father_mobile: '',
      pagination: {
        total: 0,
        pageSize: 20,
        currentPage: 1,
        pageSizes: [10, 20, 30]
      },
      gridData: []
    }
  },
  computed: {},
  created() {
    this.getData()
  },
  methods: {
    search() {
      this.getData()
    },
    // 分页导航
    handleCurrentChange(val) {
      this.pagination.currentPage = val
      this.getData()
    },
    handleSizeChange(val) {
      this.pagination.pageSize = val
      this.getData()
    },
    // 获取数据
    getData() {
      this.loading = true
      userTiedCardList({
        page: this.pagination.currentPage,
        pageSize: this.pagination.pageSize,
        mobile: this.mobile,
        real_name: this.real_name,
        card_number: this.card_number,
        type: this.type
      }).then(res => {
        this.loading = false
        this.tableData = res.data.list
        this.levelOptions = res.data.level
        this.pagination.total = res.data.pagination.total
      })
    },

    /**
     * 重置
     */
    handleReset() {
      this.page = 1
      this.pageSize = 20
      this.mobile = ''
      this.real_name = ''
      this.card_number = ''
      this.level = ''
      this.getData()
    },

    /**
     * 搜索
     */
    handleSearch() {
      // this.$router.replace({ query: '' })
      this.getData()
    },

    planStatusFormat(row, column) {
      if (row.plan_status === 0) {
        return <el-tag>未执行</el-tag>
      } else if (row.plan_status === 1) {
        return <el-tag type="warning">已制定</el-tag>
      } else if (row.plan_status === 2) {
        return <el-tag type="success">进行中</el-tag>
      } else if (row.plan_status === 3) {
        return <el-tag type="danger">已完成</el-tag>
      } else if (row.plan_status === 4) {
        return <el-tag type="danger">已取消</el-tag>
      } else if (row.plan_status === 5) {
        return <el-tag type="danger">已失败</el-tag>
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 100px;
  display: inline-block;
}
.w200 {
  width: 200px;
}

.del-dialog-cnt {
  font-size: 16px;
  text-align: center;
}
.table {
  width: 100%;
  font-size: 14px;
}
.red {
  color: #ff0000;
}
.mr10 {
  margin-right: 10px;
}
</style>
